package com.tiocloud.chat.feature.search.curr.group;

import android.graphics.Color;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.watayouxiang.httpclient.model.response.MailListResp;
import com.tiocloud.chat.R;
import com.tiocloud.chat.util.KeywordUtil;
import com.tiocloud.chat.util.StringUtil;
import com.watayouxiang.androidutils.widget.imageview.TioImageView;

import java.util.List;
import java.util.Locale;

/**
 * author : TaoWang
 * date : 2020-02-14
 * desc :
 */
public class GroupListAdapter extends BaseQuickAdapter<MailListResp.Group, BaseViewHolder> {

    private final String keyWord;

    public GroupListAdapter(@Nullable List<MailListResp.Group> data, String keyWord) {
        super(R.layout.tio_search_group_item, data);
        this.keyWord = keyWord;
    }

    @Override
    protected void convert(BaseViewHolder helper, MailListResp.Group item) {
        setItemData(helper, item, keyWord);
    }

    public static void setItemData(BaseViewHolder helper, MailListResp.Group item, String keyWord) {
        TioImageView hiv_avatar = helper.getView(R.id.hiv_avatar);
        TextView tv_name = helper.getView(R.id.tv_name);
        TextView tv_subtitle = helper.getView(R.id.tv_subtitle);

        hiv_avatar.load_tioAvatar(item.avatar);

        tv_name.setText(KeywordUtil.matcherSearchTitle(
                Color.parseColor("#FF4C94FF"),
                StringUtil.nonNull(item.name),
                keyWord));

        tv_subtitle.setText(KeywordUtil.matcherSearchTitle(
                Color.parseColor("#FF4C94FF"),
                String.format(Locale.getDefault(), "%d人", item.joinnum),
                keyWord));
    }
}
